<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll">
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      v-model.trim="$store.state.taskName"
      @keydown.enter="addTask"
    />
  </header>
</template>

<script>
export default {
  methods: {
    addTask() {
      if(!this.$store.state.taskName) return alert('任务名不能为空')
      this.$store.commit('ADD_TASK', this.$store.state.taskName)
      this.$store.state.taskName=''
    }
  },
  computed: {
        isAll: {
            set(checkedAll) {
                this.$store.getters.List.forEach((item) => (item.isDone = checkedAll))
            },
            get() {
                return this.$store.getters.List.every((item) => item.isDone === true)
            },
        },
    },
}
</script>
